package com.china08.yxyapi.api.manage.tec.teaching.scoreport.selectexam;

import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.scoreport.Exam;
import com.china08.yxyapi.repository.mg.scoreport.ExamRepository;
import com.china08.yxyapi.service.mg.impl.ExamServiceImpl;

/**
 * 导出考试模板
 * 
 */
@CrossOrigin
@RestController
public class ExportExamController {

    @Autowired
    private ExamRepository examRepository;

    @Autowired
    private ExamServiceImpl examServiceImpl;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/scoreport/selectexam/exportexam", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response, @RequestParam String idStrs)
            throws ParseException, IOException {

        String[] idArr = idStrs.split(",");
        List<String> idLst = Arrays.asList(idArr);

        if (idLst.size() == 0) { return; }
        List<Exam> examLst = examRepository.findByIdIn(idLst);
        if (examLst.size() == 0) { return; }
        // 下载Excel
        examServiceImpl.downloadExamExcel(request, response, examLst);
    }
}
